package com.ktg.mes.pda.service.impl;

import java.util.Arrays;
import java.util.List;
import com.ktg.common.utils.DateUtils;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ktg.common.utils.SecurityUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ktg.mes.pda.mapper.PdaLabelTypeBomMapper;
import com.ktg.mes.pda.domain.PdaLabelTypeBom;
import com.ktg.mes.pda.service.IPdaLabelTypeBomService;



/**
 * PDA采集标签内容Service业务层处理
 *
 * @author byteco
 * @date 2023-03-03
 */
@Service
public class PdaLabelTypeBomServiceImpl extends ServiceImpl<PdaLabelTypeBomMapper, PdaLabelTypeBom> implements IPdaLabelTypeBomService
{




    /**
     * 查询PDA采集标签内容
     *
     * @param entity PDA采集标签内容
     * @param page 分页对象
     * @return PDA采集标签内容
     */
    @Override
    public IPage<PdaLabelTypeBom> queryPageList(PdaLabelTypeBom entity, Page<PdaLabelTypeBom> page) {
        QueryWrapper<PdaLabelTypeBom> lqw = new QueryWrapper<PdaLabelTypeBom>(entity);
        lqw.orderByDesc("create_time");
        IPage<PdaLabelTypeBom> pageList = this.page(page, lqw);
        return pageList;
    }

    /**
     * 查询PDA采集标签内容
     *
     * @param entity PDA采集标签内容
     * @return PDA采集标签内容
     */
    @Override
    public List<PdaLabelTypeBom> queryList(PdaLabelTypeBom entity) {
        QueryWrapper<PdaLabelTypeBom> lqw = new QueryWrapper<PdaLabelTypeBom>(entity);
        lqw.orderByDesc("create_time");
        return this.list(lqw);
    }

    public PdaLabelTypeBom getInfo(Long id)
    {
        return this.getById(id);
    }


    /**
     * 新增PDA采集标签内容
     *
     * @param entity PDA采集标签内容
     * @return 结果
     */
    @Override
    public void insert(PdaLabelTypeBom entity)
    {
        entity.setCreateBy(SecurityUtils.getUsername());
        entity.setCreateTime(DateUtils.getNowDate());
        this.save(entity);
    }

    /**
     * 修改PDA采集标签内容
     *
     * @param entity PDA采集标签内容
     * @return 结果
     */
    @Override
    public boolean update(PdaLabelTypeBom entity)
    {
        entity.setUpdateBy(SecurityUtils.getUsername());
        entity.setUpdateTime(DateUtils.getNowDate());
        return this.updateById(entity);
    }

    /**
     * 批量删除PDA采集标签内容
     *
     * @param recordIds 需要删除的PDA采集标签内容主键
     * @return 结果
     */
    @Override
    public boolean delete(Long[] recordIds)
    {

        return this.removeByIds(Arrays.asList(recordIds));
    }

    /**
     * 删除PDA采集标签内容信息
     *
     * @param recordId PDA采集标签内容主键
     * @return 结果
     */
    @Override
    public boolean delete(Long recordId)
    {
        return this.removeById(recordId);
    }


    /**
     * 生成采集标签规则
     * @param labelTypeId
     * @return
     */
    public PdaLabelTypeBom findTypeBomGroup(Long labelTypeId){
        return getBaseMapper().findTypeBomGroup(labelTypeId);
    };
    private LambdaQueryWrapper<PdaLabelTypeBom> buildQueryWrapper(PdaLabelTypeBom entity) {
        LambdaQueryWrapper<PdaLabelTypeBom> lqw = Wrappers.lambdaQuery();
                    lqw.eq(entity.getLabelTypeId() != null, PdaLabelTypeBom::getLabelTypeId, entity.getLabelTypeId());
                    lqw.like(StringUtils.isNotBlank(entity.getName()), PdaLabelTypeBom::getName, entity.getName());
                    lqw.eq(StringUtils.isNotBlank(entity.getIndexNum()), PdaLabelTypeBom::getIndexNum, entity.getIndexNum());
        return lqw;
    }
}
